<?

  $currentWealth = $this->character->getMoney();
  
?>
<div style="float: right; width: 250px; height: 50px; margin-top: 8px;">
  <div align="center"><b>Poverty Indicator:</b><br/>
  You have <?= getDefault($currentWealth, 'ZERO') ?> gold to spend.</div>
</div>
&nbsp;
<h3>Buy Stuff</h3>
<table width="650"><?

foreach(DB_GetList('SELECT * FROM '.getTableName('shopitems').
  ' LEFT JOIN '.getTableName('items').' ON (s_item=i_key)
  LEFT JOIN '.getTableName('inventory').' ON (s_item=iv_item AND iv_character='.$this->character->charDS['c_key'].')
  WHERE s_zone="'.$this->character->charDS['c_location'].'"
  ORDER BY i_value') as $itemDS) if ($itemDS['i_value'] > 0)
{
  ?><tr>
    <td valign="top" width="40"><img width="32" src="img/<?= $itemDS['i_icon'] ?>.png"/></td>
    <td valign="top" width="*">
      <b><?= $itemDS['i_name'] ?></b><br/>
      <?= $itemDS['i_description'] ?>
    </td>
    <td valign="top" width="32">
    <? 
      $itxt = $this->character->explainItem($itemDS);
      if ($itxt != '') {
        ?><img src="img/icons/restart.png" <?= ToolTip(':'.$itxt) ?>/><?
    } ?>    
    </td>
    <td valign="top" nowrap width="130">
    <?
    if ($currentWealth < $itemDS['i_value'])
    {
      ?><b style="color: gray"><?= $itemDS['i_value']?> gold</b><?
    }
    else
    {
      ?><input type="button" name="buy" style="width: 120px" 
        onclick="document.location='<?= actionUrl('index', 'shop', 'buy='.$itemDS['i_key']) ?>';"
        value="buy for <?= $itemDS['i_value'] ?> gold"/><?
    }
    ?></td>
    <td valign="top" width="150">
      <?
      if ($itemDS['iv_key'] > 0)
        print('You already have '.$itemDS['iv_quantity'].' of these.');
      ?>
    </td>
  </tr><?
}

?></table>

<h3>Sell Stuff</h3>
<table width="650">
<?
if (sizeof($this->character->invList)>0)
{
  foreach($this->character->invList as $k => $invDS) if ($invDS['i_value'] != 0 && ($invDS['iv_on'] == 'N' || $invDS['iv_quantity'] > 1))
  {
    $itxt = $this->character->explainItem($invDS);
    if ($itxt != '') $itxt = toolTip(':'.$itxt);
    ?><tr>
      <td valign="top" width="40"><img width="32" <?= $itxt ?> src="img/<?= $invDS['i_icon'] ?>.png"/></td>
      <td valign="top" width="*">
        <span <?= $itxt ?>><b><?= $invDS['i_name'] ?></b> <? if ($invDS['iv_quantity'] != 1) print('('.$invDS['iv_quantity'].'x)'); ?><br/>
        <?= $invDS['i_description'] ?></span>
      </td>
      <td valign="top" width="32">
      <? 
        if ($itxt != '') {
          ?><img src="img/icons/restart.png" <?= $itxt ?>/><?
      } ?>    
      </td>
      <td valign="top" nowrap width="130">
        <input type="button" name="sell" style="width: 120px" 
          onclick="document.location='<?= actionUrl('index', 'shop', 'sell='.$invDS['i_key']) ?>';"
          value="sell for <?= round($invDS['i_value']/2) ?> gold"/>
      </td>
      <td valign="top" width="150">
      <?
      if ($invDS['iv_on'] == 'Y')
        print('One of them is currently in use.');
      ?>
      </td>
    </tr><?
  }
}
else
  print('<tr><td style="color: gray">Actually, you don\'t own anything!</td></tr>');
?>
</table>